﻿using UnityEngine;
using System.Collections;

using UnityEngine.UI;

public class UIDepth : MonoBehaviour
{
	public int order;
	public bool isUI = true;

	void Start()
	{
//		SetDepth(order);
	}

	public void SetDepth(int order)
	{
		this.order = order;

		if(isUI)
		{
			Canvas canvas = GetComponent<Canvas>();
			if(canvas == null)
			{
				canvas = gameObject.AddComponent<Canvas>();
			}
			canvas.overrideSorting = true;
			canvas.sortingOrder = this.order;
		}
		else
		{
			// 粒子特效等 //
			Renderer []renders  =  GetComponentsInChildren<Renderer>();
			
			foreach(Renderer render in renders)
			{
				render.sortingOrder = this.order;
			}
		}
	}
}